package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.baihang.smeis002.BaiHangSMEIS002EntInfo;
import com.ucredit.babel.common.model.third.baihang.smeis002.BaiHangSMEIS002RelationInfo;
import com.ucredit.babel.common.model.third.baihang.smeis002.BaihangSMEIS002Data;
import com.ucredit.babel.common.model.third.baihang.smeis002.BaihangSMEIS002Record;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Classname BaihangSMEIS002Parse
 * @Description 百行人企核验征信
 * @Created by xj
 */
public class BaihangSMEIS002Parse extends ParseBase {
    Text key = new Text();
    Text value = new Text();

    @Override
    public boolean parseJob(Mapper.Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BaihangSMEIS002Record obj = (BaihangSMEIS002Record) model;
        BaihangSMEIS002Data data = obj.getData();
        BaiHangSMEIS002EntInfo entInfo = null;
        BaiHangSMEIS002RelationInfo relationInfo = null;
        if (data != null) {
            entInfo = data.getEntInfo();
            relationInfo = data.getRelationInfo();
        }
        StringBuilder sb = getBaseInfo(obj, successful);

        sb.append(entInfo == null ? "" : entInfo.getMatched()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getEntMark1()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getEntMark2()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getEntName()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getCreditCode()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getRegNo()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getEntStatus()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getEntType()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getEsDate()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getOpFrom()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getOpTo()).append(CRT001);
        sb.append(entInfo == null ? "" : entInfo.getRegAdd()).append(CRT001);

        sb.append(relationInfo == null ? "" : relationInfo.getName()).append(CRT001);
        sb.append(relationInfo == null ? "" : relationInfo.getId()).append(CRT001);
        sb.append(relationInfo == null ? "" : relationInfo.getLp()).append(CRT001);
        sb.append(relationInfo == null ? "" : relationInfo.getExec()).append(CRT001);
        sb.append(relationInfo == null ? "" : relationInfo.getSh()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        value.set((sb.toString() + txSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, value);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_baihang_smeis002_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIHANG_SMEIS002_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百行人企核验征信";
    }
}
